package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    //查询所有套餐
    @GetMapping("/setmeal/page")
    public ResultInfo findByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            String name){
        Page<Setmeal> page = setmealService.findByPage(pageNum,pageSize,name);
        return ResultInfo.success(page);
    }

    //新增套餐
    @PostMapping("setmeal")
    public ResultInfo save(@RequestBody Setmeal setmeal){
        setmealService.save(setmeal);
        return ResultInfo.success(null);
    }

    //批量删除
    @DeleteMapping("/setmeal")
    public ResultInfo deleteByIds(Long[] ids){
        if (ids != null && ids.length > 0 ){
            setmealService.deleteByIds(ids);
        }
        return ResultInfo.success(null);

    }

    //批量停售/起售
    @PostMapping("/setmeal/status/{type}")
    public ResultInfo updateByStatus(@PathVariable("type") Integer status,Long[] ids){
        setmealService.updateByStatus(status,ids);
        return ResultInfo.success(null);
    }

    //修改回显
    @GetMapping("/setmeal/{id}")
    public ResultInfo findBySetmealId(@PathVariable("id") Long id){
        Setmeal setmeal = setmealService.findBySetmealId(id);
        return ResultInfo.success(setmeal);
    }

    //套餐信息修改(update)
    @PutMapping("setmeal")
    public ResultInfo update(@RequestBody Setmeal setmeal){
        setmealService.update(setmeal);
        return ResultInfo.success(null);

    }




}
